import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import get from '@dfeidao/atom-web/local/get';
import set from '@dfeidao/atom-web/local/set';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import p001 from './p001';

export default async function a008(fd: IFeidaoAiBrowserComponent, e: Event) {// 用于列的排序
	// 获取触发对象中的值
	const d = e.currentTarget as HTMLElement; // 数据转换
	const type = d.getAttribute('data-no');// 获取当前是正序或倒序
	const name = d.getAttribute('data-name');
	let pn = get(fd, 'pn');// 获取当前页码
	if (pn === undefined) {
		pn = 1;
	}
	let equip_depart = get(fd, 'equip_depart');
	if (equip_depart === undefined) {
		equip_depart = "";
	}
	let project = get(fd, 'project');
	if (project === undefined) {
		project = "";
	}
	let assetsname = get(fd, 'assetsname');
	if (assetsname === undefined) {
		assetsname = "";
	}
	let asset_classification = get(fd, 'asset_classification');
	if (asset_classification === undefined) {
		asset_classification = "";
	}
	let timeout_alert = get(fd, 'timeout_alert');
	if (timeout_alert === undefined) {
		timeout_alert = "";
	}
	let customer_assets = get(fd, 'customer_assets');
	if (customer_assets === undefined) {
		customer_assets = "";
	}
	if (type === "0") {// 转换下次点击的排序方式
		d.setAttribute("data-no", "1");
		// 获取排序后的数据
		const res = await nodejs<{ dt: Array<{}>; coun: number }>(
			'project-assets/zj-000002/s001', {
				filter: {
					responsible_no: "YG00000077",
					equip_depart,
					project,
					assetsname,
					asset_classification,
					timeout_alert,
					customer_assets,
					type,
					name,
					pn
				}
			});
		render(fd, res.dt, p001, 'p001', 'inner');
	} else {
		d.setAttribute("data-no", "0");
		// 获取排序后的数据
		const res = await nodejs<{ dt: Array<{}>; coun: number }>(
			'project-assets/zj-000002/s001', {
				filter: {
					responsible_no: "YG00000077",
					equip_depart,
					project,
					assetsname,
					asset_classification,
					timeout_alert,
					customer_assets,
					type,
					name,
					pn
				}
			});
		render(fd, res.dt, p001, 'p001', 'inner');
	}
	set(fd, 'type',type);
	set(fd,'name',name);
}
